<?php


namespace App\Http\Controllers\School;


use App\Http\Controllers\Controller;
use App\Services\SchoolService;
use Illuminate\Http\Request;

class IndexController extends Controller
{
    //添加学校信息
    public function addSchool(Request $request)
    {
        try {
            $this->validate($request, [
                'school_title' => 'required|string',//学校名称
                'mind_teacher' => 'required',//心理老师
                'mind_tel' => 'required',//心理老师电话
                'recheck_teacher' => 'required',//复检师
                'recheck_tel' => 'required',//复检师电话
                'need_device' => 'required',//是否需要设备
            ]);
        } catch (\Exception $e) {
            return output(0, "请检查参数,必填参数不能为空！", null);
        }
        $input = $request->all();
        if (!empty($input['mind_tel']) && !isMobile($input['mind_tel'])) {
            return output(0, '心理老师手机号不合法', null);
        }
        if (!empty($input['recheck_tel']) && !isMobile($input['recheck_tel'])) {
            return output(0, '复检师手机号不合法', null);
        }
        try {
            $input['tax_number'] =  $input['tax_number']??'111111111111111111';
            $schoolId = (new SchoolService())->addSchoolInfo( $input);
            return output(1, '提交成功！', ['schoolId'=>$schoolId]);
        }catch (\Exception $e){
            x($e->getMessage());
            return output(0, '添加失败,请重新扫码提交！', null);
        }
    }
}